import {
  getDetails
} from '@/api/admin/user'
var validatePhoe = (rule, value, callback) => {
  // let phoeReg=/^[1][3-9][0-9]{9}$/
  // if(value==''||value==undefined||value==null){
  callback()

}
var validateUsername = (rule, value, callback) => {
  getDetails(value).then(response => {
    if (window.boxType === 'edit') callback()
    const result = response.data.data
    console.log(result)
    let userNamereg = /^\S+$/
    if (result !== null) {
      callback(new Error('用户名已经存在'))
    } else {
      if (!userNamereg.test(value)) {
        callback(new Error('不允许有空格'))
      } else {
        callback()
      }
    }
  })
};

export const tableOption = {
  border: true,
  index: true,
  indexLabel: '序号',
  stripe: true,
  menuAlign: 'center',
  editBtn: false,
  delBtn: false,
  align: 'center',
  addBtn: false,
  column: [
    {
      fixed: true,
      label: 'id',
      prop: 'id',
      span: 24,
      hide: true,
      editDisplay: false,
      addDisplay: false
    },
    {
      fixed: true,
      label: '用户名',
      prop: 'username',
      editDisabled: true,
      slot: true,
      search: true,
      span: 24,
      rules: [
        { required: true, message: '请输入用户名' },
        { min: 3, max: 20, message: '长度在 3 到 20 个字符', trigger: 'blur' },
        { validator: validateUsername, trigger: 'blur' }
      ]
    },
    {
      fixed: true,
      label: '姓名',
      prop: 'realName',
      slot: true,
      search: true,
      span: 24,
      rules: [{ required: true, message: '请输入姓名' }]
    },
    {
      label: '密码',
      prop: 'password',
      type: 'password',
      value: '',
      hide: true,
      span: 24,
      /* rules: [{
         min: 6,
         max: 20,
         message: '长度在 6 到 20 个字符',
         trigger: 'blur'
       }]*/
    },
    {
      label: '所属主部门',
      width: 120,
      prop: 'deptId',
      formslot: true,
      slot: true,
      span: 24,
      hide: false,
      dataType: "number",
      rules: [{ required: true, message: '请选择部门', trigger: 'change' }]
    },
    {
      label: 'his系统工号',
      width: 120,
      prop: 'hisWorkNumber',
      slot: true,
      span: 24,
      value: ''
    },
    {
      label: '手机号',
      width: 120,
      prop: 'phone',
      type: 'tel',
      value: '',
      span: 24,
      rules: [{
          min: 11,
          max: 11,
          message: '长度在 11 个字符',
          trigger: 'blur'
        },
        {
          validator: validatePhoe,
          trigger: 'blur'
        }

      ]
    },
    // {
    //   label: '组织',
    //   width: 220,
    //   prop: 'org',
    //   formslot: true,
    //   slot: true,
    //   span: 24,
    //   hide: false,
    //   dataType:"number",
    //   rules: [{
    //     required: true,
    //     message: '请选择组织',
    //     trigger: 'change'
    //   }]
    // },
    /* {
       label: '角色',
       prop: 'role',
       formslot: true,
       slot: true,
       overHidden: true,
       span: 24,
       rules: [{
         required: true,
         message: '请选择角色',
         trigger: 'blur'
       }]
     },*/
    {
      width: 180,
      label: '单位',
      prop: 'unitId',
      formslot: true,
      slot: true,
      span: 24,
      hide: false,
      dataType: "number",
      rules: [{
        required: true,
        message: '请选择单位',
        trigger: 'change'
      }]
    },
    {
      width: 180,
      label: '岗位类型',
      prop: 'jobType',
      formslot: true,
      slot: true,
      span: 24,
      hide: false,
      dataType: "number",
      rules: [{
        required: true,
        message: '请选择岗位',
        trigger: 'change'
      }]
    },
    {
      width: 180,
      label: '岗位',
      prop: 'posId',
      formslot: true,
      slot: true,
      span: 24,
      hide: false,
      dataType: "number",
    },
    {
      width: 180,
      label: '角色',
      prop: 'role',
      formslot: true,
      slot: true,
      span: 24,
      hide: false,
      dataType: "number",
      rules: [{
        required: true,
        message: '请选择角色',
        trigger: 'change'
      }]
    },
    {
      label: '状态',
      prop: 'lockFlag',
      type: 'radio',
      slot: true,
      border: true,
      span: 24,
      rules: [{
        required: true,
        message: '请选择状态',
        trigger: 'blur'
      }],
      dicData: [{
        label: '有效',
        value: '0'
      }, {
        label: '锁定',
        value: '9'
      }]
    }, {
      width: 180,
      label: '创建时间',
      prop: 'createTime',
      type: 'datetime',
      format: 'yyyy-MM-dd HH:mm',
      valueFormat: 'yyyy-MM-dd HH:mm:ss',
      editDisabled: true,
      addDisplay: false,
      span: 24
    }

  ],

}
